package com.touchwise.screen_info;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.TextView;

/**
 * 屏幕尺寸数据
 * Created by esirong on 2016/2/22.
 */
public class MainActivity extends Activity {
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout);
        textView = (TextView) findViewById(R.id.original);
        showScreenInfo();
    }

    private void showScreenInfo() {
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        textView.setText("" + metrics);
        textView = (TextView) findViewById(R.id.resolution);
        String str1 = metrics.widthPixels + " x " + metrics.heightPixels;
        textView.setText(str1);

        if (metrics.density > 0.0001D) {
            float f6 = metrics.widthPixels / metrics.density;
            float f7 = metrics.heightPixels / metrics.density;
            String str6 = (int) f6 + " x " + (int) f7;
            ((TextView) findViewById(R.id.resolution_dpi)).setText(str6);
        }

        //屏幕密度DPI
        String str2 = metrics.densityDpi + " ";
        ((TextView) findViewById(R.id.density_dpi)).setText(str2);

        //对角线
        double result = Math.sqrt(Math.pow(metrics.widthPixels, 2) + Math.pow(metrics.heightPixels, 2)) / metrics.densityDpi;

        ((TextView) findViewById(R.id.diagonal)).setText("" + result);
        //宽高（英寸)
        float f1 = metrics.widthPixels / metrics.xdpi;
        float f2 = metrics.heightPixels / metrics.ydpi;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(f1).append("x").append(f2);

        ((TextView) findViewById(R.id.resolution_inches)).setText(stringBuilder);

        //宽高（cm)
        float f3 = f1 * 2.54F;
        float f4 = f2 * 2.54F;
        stringBuilder = new StringBuilder();
        stringBuilder.append(f3).append("x").append(f4);

        ((TextView) findViewById(R.id.resolution_cm)).setText(stringBuilder);

        //small
        if (metrics.density < 1) {
            ((TextView) findViewById(R.id.screen_size21)).setText("ldpi");
        }
        //normal
        if (metrics.density == 1) {
            ((TextView) findViewById(R.id.screen_size21)).setText("mdpi");
        }
        //large
        if (metrics.density == 1.5) {
            ((TextView) findViewById(R.id.screen_size21)).setText("hdpi");
        }
        //X-larger
        if (metrics.density == 2) {
            ((TextView) findViewById(R.id.screen_size21)).setText("xhdpi");
        }
        //Xx-larger
        if (metrics.density == 3) {
            ((TextView) findViewById(R.id.screen_size21)).setText("xxhdpi");
        }
        //Xx-larger
        if (metrics.density == 4) {
            ((TextView) findViewById(R.id.screen_size21)).setText("xxxhdpi");
        }

        //
        //2,4,7,10对角线
        double rate = Math.sqrt(Math.pow(metrics.widthPixels, 2) + Math.pow(metrics.heightPixels, 2)) / metrics.densityDpi;
        //small
        if (rate >= 2 && rate < 4) {
            ((TextView) findViewById(R.id.screen_size)).setText("small");
        }
        //normal
        if (rate >= 4 && rate < 7) {
            ((TextView) findViewById(R.id.screen_size)).setText("normal");
        }
        //large
        if (rate >= 7 && rate < 10) {
            ((TextView) findViewById(R.id.screen_size)).setText("large");
        }
        //xlarge
        if (rate >= 10) {
            ((TextView) findViewById(R.id.screen_size)).setText("xlarge");
        }
    }

}
